using FirstTea.Application.DTOs;
using FirstTea.Application.Interfaces;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace FirstTea.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class ConversationController : ControllerBase
    {
        private readonly IConversationService _conversationService;
        public ConversationController(IConversationService conversationService)
        {
            _conversationService = conversationService;
        }
        [HttpGet("{id}")]
        public async Task<ActionResult<ConversationDto?>> GetById(Guid id)
        {
            var conv = await _conversationService.GetByIdAsync(id);
            if (conv == null) return NotFound();
            return Ok(conv);
        }
        [HttpGet("user/{userId}")]
        public async Task<ActionResult> GetByUser(Guid userId)
        {
            var convs = await _conversationService.GetByUserAsync(userId);
            return Ok(convs);
        }
        [HttpPost]
        public async Task<ActionResult> Create([FromBody] ConversationDto dto)
        {
            await _conversationService.CreateAsync(dto);
            return Ok();
        }
        [HttpDelete("{id}")]
        public async Task<ActionResult> Delete(Guid id)
        {
            await _conversationService.DeleteAsync(id);
            return Ok();
        }
    }
}
